package de.openlaboratory.cmis.repository;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.ItemIterable;

public class LocalFileList<T> implements ItemIterable<CmisObject>
{
	private List <Path> fileList;
	private FileIterator fileIter;
	private long pos;
	private long pageSize = 500;

	public LocalFileList(List<Path> files)
	{
		this.fileList = files;
		this.fileIter = new FileIterator(fileList);
		pos=0;
	}

	@Override
	public boolean getHasMoreItems()
	{
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public ItemIterable<CmisObject> getPage()
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public ItemIterable<CmisObject> getPage(int arg0)
	{
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getPageNumItems()
	{
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public long getTotalNumItems()
	{
		// TODO Auto-generated method stub
		return -1;
	}

	@Override
	public Iterator<CmisObject> iterator()
	{
		return fileIter.iterator();
	}

	@Override
	public ItemIterable<CmisObject> skipTo(long arg0)
	{
		// TODO Auto-generated method stub
		return null;
	}

	public long getPageSize()
	{
		return pageSize;
	}

	public void setPageSize(long pageSize)
	{
		this.pageSize = pageSize;
	}

}

class FileIterator implements Iterable<CmisObject>
{
	private ArrayList<CmisObject> files;
	
	public FileIterator(List<Path> fileList)
	{
		files = new ArrayList<CmisObject>();
		
		for(Path p : fileList)
		{
			CmisObject f = new LocalFile(p);
			this.files.add(f);
		}
	}

	@Override
	public Iterator<CmisObject> iterator()
	{
		Iterator<CmisObject> fileIter = files.iterator();
        return fileIter;
	}
	
}